GetLinearizedSubtree(PredicateAnalyzer<PdfTreeNodeBase>) Метод (PdfTreeNodeBase)
В этом разделе
Возвращает линеаризованное поддерево, которое начинается с текущего узла и содержит только узлы, разрешенные .
Синтаксис
Parameters
- predicate
- Предикат, определяющий узлы дерева, которые должны содержаться в линеаризованном поддереве.
Return Value
Линеаризованное поддерево.
Ремарки
Если предикат не указан, метод возвращает все подузлы.
Пример
Вот пример, показывающий, как получить все узлы PdfResource с ZIP-сжатием:
''' <summary>
''' A predicate that checks taget compression type.
''' </summary>
Public Class ResourceCompressionAnalyzer
Inherits Vintasoft.Imaging.Processing.Analyzers.PredicateAnalyzer(Of Vintasoft.Imaging.Pdf.Tree.PdfTreeNodeBase)
''' <summary>
''' Compression types, which should be analyzed.
''' </summary>
Private _compressions As Vintasoft.Imaging.Pdf.PdfCompression()
''' <summary>
''' Initializes a new instance of the <see cref="ResourceCompressionAnalyzer"/> class.
''' </summary>
''' <param name="compressions">Compression types, which should be analyzed.</param>
Public Sub New(compressions As Vintasoft.Imaging.Pdf.PdfCompression())
MyBase.New("PDF resource compression analyzer")
_compressions = compressions
End Sub
''' <summary>
''' Returns all nodes that are <see cref="Vintasoft.Imaging.Pdf.Tree.PdfResource"/>
''' with ZIP compression.
''' </summary>
''' <param name="document">A PDF document.</param>
''' <returns>
''' All <see cref="Vintasoft.Imaging.Pdf.Tree.PdfResource"/>
''' with ZIP compression.
''' </returns>
Public Function GetPdfResourcesWithZipCompression(document As Vintasoft.Imaging.Pdf.PdfDocument) As Vintasoft.Imaging.Pdf.Tree.PdfTreeNodeBase()
Dim compressions As Vintasoft.Imaging.Pdf.PdfCompression() = New Vintasoft.Imaging.Pdf.PdfCompression() {Vintasoft.Imaging.Pdf.PdfCompression.Zip}
Return document.Catalog.GetLinearizedSubtree(New ResourceCompressionAnalyzer(compressions))
End Function
''' <summary>
''' Analyzes the specified target.
''' </summary>
''' <param name="target">The target object.</param>
''' <returns>
''' Logical result of analysis.
''' </returns>
Protected Overrides Function Analyze(target As Vintasoft.Imaging.Pdf.Tree.PdfTreeNodeBase) As Boolean
' if target is PdfResource
If TypeOf target Is Vintasoft.Imaging.Pdf.Tree.PdfResource Then
' get PDF resource compression
Dim pdfResourceCompression As Vintasoft.Imaging.Pdf.PdfCompression = DirectCast(target, Vintasoft.Imaging.Pdf.Tree.PdfResource).Compression
' for each compression type, which should be analyzed
For Each compression As Vintasoft.Imaging.Pdf.PdfCompression In _compressions
' if PDF resource uses compression
If pdfResourceCompression = compression Then
Return True
End If
Next
End If
Return False
End Function
End Class
/// <summary>
/// A predicate that checks taget compression type.
/// </summary>
public class ResourceCompressionAnalyzer : Vintasoft.Imaging.Processing.Analyzers.PredicateAnalyzer<Vintasoft.Imaging.Pdf.Tree.PdfTreeNodeBase>
{
/// <summary>
/// Compression types, which should be analyzed.
/// </summary>
Vintasoft.Imaging.Pdf.PdfCompression[] _compressions;
/// <summary>
/// Initializes a new instance of the <see cref="ResourceCompressionAnalyzer"/> class.
/// </summary>
/// <param name="compressions">Compression types, which should be analyzed.</param>
public ResourceCompressionAnalyzer(Vintasoft.Imaging.Pdf.PdfCompression[] compressions)
: base("PDF resource compression analyzer")
{
_compressions = compressions;
}
/// <summary>
/// Returns all nodes that are <see cref="Vintasoft.Imaging.Pdf.Tree.PdfResource"/>
/// with ZIP compression.
/// </summary>
/// <param name="document">A PDF document.</param>
/// <returns>
/// All <see cref="Vintasoft.Imaging.Pdf.Tree.PdfResource"/>
/// with ZIP compression.
/// </returns>
public Vintasoft.Imaging.Pdf.Tree.PdfTreeNodeBase[] GetPdfResourcesWithZipCompression(Vintasoft.Imaging.Pdf.PdfDocument document)
{
Vintasoft.Imaging.Pdf.PdfCompression[] compressions = new Vintasoft.Imaging.Pdf.PdfCompression[] {
Vintasoft.Imaging.Pdf.PdfCompression.Zip
};
return document.Catalog.GetLinearizedSubtree(
new ResourceCompressionAnalyzer(compressions));
}
/// <summary>
/// Analyzes the specified target.
/// </summary>
/// <param name="target">The target object.</param>
/// <returns>
/// Logical result of analysis.
/// </returns>
protected override bool Analyze(Vintasoft.Imaging.Pdf.Tree.PdfTreeNodeBase target)
{
// if target is PdfResource
if (target is Vintasoft.Imaging.Pdf.Tree.PdfResource)
{
// get PDF resource compression
Vintasoft.Imaging.Pdf.PdfCompression pdfResourceCompression =
((Vintasoft.Imaging.Pdf.Tree.PdfResource)target).Compression;
// for each compression type, which should be analyzed
foreach (Vintasoft.Imaging.Pdf.PdfCompression compression in _compressions)
{
// if PDF resource uses compression
if (pdfResourceCompression == compression)
return true;
}
}
return false;
}
}
Требования
Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
Смотрите также